/**
 * 
 */
package ModStats;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * @author admaay
 *
 * ProjetStat
 */
public class FilesPropreties {
		
	public static FileInputStream getConfigFile() {
		
		//		
		FileInputStream input = null;
		
		try {
			input = new FileInputStream("conf/config.properties");
			
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		return input;
	}
	
	public void setPropreties() {
		
		Properties prop = new Properties();
		
		//prop.setProperty("separation", ",");
		
		//save properties to project root folder
		try {
			prop.store(new FileOutputStream("conf/config.properties"), null);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static int getNbOfColumns(BufferedReader ReadIn) throws Exception {
		String aLine;
		String delims = "";
		String[] tokens = null;
		
		//
		Properties prop = new Properties();
		
		FileInputStream in = FilesPropreties.getConfigFile();
		//
		prop.load(in);
		
		delims = prop.getProperty("delimiter");
		
		//on recupère juste le nombre de colone pour la première ligne
		if((aLine = ReadIn.readLine() )!= null)			
			tokens = aLine.split(delims);
		
		if(tokens != null)
			return tokens.length;
		
		return 0;
	}
	
	/**
	 * 
	 * @param ReadIn
	 * @return
	 * 
	 * les données doivent commencer à partir de la colonne 0 ou 1
	 * si 0 => le nom i-eme colonne
	 * si 1 => le nom en O-eme colonne
	 * @throws IOException 
	 */
//	public static int getDataColumnStart(BufferedReader ReadIn) throws IOException {
//		
//		String aLine;
//		String delims = "";
//		String[] tokens = null;
//		
//		//
//		Properties prop = new Properties();
//		
//		FileInputStream in = FilesPropreties.getConfigFile();
//		//
//		prop.load(in);
//		
//		delims = prop.getProperty("delimiter");
//		
//		
//		return 0;
//	}
//	
//	public static int getDataColumnEnd(BufferedReader ReadIn) {
//		
//		return 0;
//	}
//	
//	public static int getNameColumn(BufferedReader ReadIn) {
//		
//		return 0;
//	}
}
